package com.ruoyi.factory.staffSafe.service.impl;

import java.util.List;

import com.ruoyi.factory.staffSafe.domain.StaffsafeInfo;
import com.ruoyi.factory.staffSafe.domain.StaffsafeYxtinfo;
import com.ruoyi.factory.staffSafe.mapper.StaffsafeYxtinfoMapper;
import com.ruoyi.factory.staffSafe.service.IStaffsafeYxtinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;

/**
 * 培训档案云学堂人员信息记录Service业务层处理
 * 
 * @author liujiaji
 * @date 2024-07-24
 */
@Service
public class StaffsafeYxtinfoServiceImpl implements IStaffsafeYxtinfoService
{
    @Autowired
    private StaffsafeYxtinfoMapper staffsafeYxtinfoMapper;

    /**
     * 查询培训档案云学堂人员信息记录
     * 
     * @param id 培训档案云学堂人员信息记录主键
     * @return 培训档案云学堂人员信息记录
     */
    @Override
    public StaffsafeYxtinfo selectStaffsafeYxtinfoById(String id)
    {
        return staffsafeYxtinfoMapper.selectStaffsafeYxtinfoById(id);
    }

    /**
     * 查询培训档案云学堂人员信息记录列表
     * 
     * @param staffsafeYxtinfo 培训档案云学堂人员信息记录
     * @return 培训档案云学堂人员信息记录
     */
    @Override
    public List<StaffsafeYxtinfo> selectStaffsafeYxtinfoList(StaffsafeYxtinfo staffsafeYxtinfo)
    {
        return staffsafeYxtinfoMapper.selectStaffsafeYxtinfoList(staffsafeYxtinfo);
    }

    /**
     * 新增培训档案云学堂人员信息记录
     * 
     * @param staffsafeYxtinfo 培训档案云学堂人员信息记录
     * @return 结果
     */
    @Transactional
    @Override
    public int insertStaffsafeYxtinfo(StaffsafeYxtinfo staffsafeYxtinfo)
    {
        int rows = staffsafeYxtinfoMapper.insertStaffsafeYxtinfo(staffsafeYxtinfo);
        insertStaffsafeInfo(staffsafeYxtinfo);
        return rows;
    }

    /**
     * 修改培训档案云学堂人员信息记录
     * 
     * @param staffsafeYxtinfo 培训档案云学堂人员信息记录
     * @return 结果
     */
    @Transactional
    @Override
    public int updateStaffsafeYxtinfo(StaffsafeYxtinfo staffsafeYxtinfo)
    {
        staffsafeYxtinfoMapper.deleteStaffsafeInfoByUserCode(staffsafeYxtinfo.getId());
        insertStaffsafeInfo(staffsafeYxtinfo);
        return staffsafeYxtinfoMapper.updateStaffsafeYxtinfo(staffsafeYxtinfo);
    }

    /**
     * 批量删除培训档案云学堂人员信息记录
     * 
     * @param ids 需要删除的培训档案云学堂人员信息记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteStaffsafeYxtinfoByIds(String[] ids)
    {
        staffsafeYxtinfoMapper.deleteStaffsafeInfoByUserCodes(ids);
        return staffsafeYxtinfoMapper.deleteStaffsafeYxtinfoByIds(ids);
    }

    /**
     * 删除培训档案云学堂人员信息记录信息
     * 
     * @param id 培训档案云学堂人员信息记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteStaffsafeYxtinfoById(String id)
    {
        staffsafeYxtinfoMapper.deleteStaffsafeInfoByUserCode(id);
        return staffsafeYxtinfoMapper.deleteStaffsafeYxtinfoById(id);
    }

    /**
     * 新增培训档案人员信息信息
     * 
     * @param staffsafeYxtinfo 培训档案云学堂人员信息记录对象
     */
    public void insertStaffsafeInfo(StaffsafeYxtinfo staffsafeYxtinfo)
    {
        List<StaffsafeInfo> staffsafeInfoList = staffsafeYxtinfo.getStaffsafeInfoList();
        String id = staffsafeYxtinfo.getId();
        if (StringUtils.isNotNull(staffsafeInfoList))
        {
            List<StaffsafeInfo> list = new ArrayList<StaffsafeInfo>();
            for (StaffsafeInfo staffsafeInfo : staffsafeInfoList)
            {
                staffsafeInfo.setUserCode(id);
                list.add(staffsafeInfo);
            }
            if (list.size() > 0)
            {
                staffsafeYxtinfoMapper.batchStaffsafeInfo(list);
            }
        }
    }
}
